/*
 * Copyright (c) 2009, Jan Pastor. All Rights Reserved.
 */

package sk.jp.jitag.dao.db4o.model;

import java.util.List;

import sk.jp.jitag.dao.db4o.Column;
import sk.jp.jitag.dao.db4o.CollectionsFactory;

public class Child extends Person {

    private static final Column _ANIMALS = new Column("animals");

    private List<DomesticAnimal> animals = null;

    //----------------------------------------------------------------------

    public Child(String name, String surname, Integer age, Sex sex) {
        super(name, surname, age, sex);
    }

    public Child setAnimals(List<DomesticAnimal> animals) {
        if(animals != null){
            this.animals = CollectionsFactory.createList(animals);
            for (DomesticAnimal animal : this.animals) {
                animal.setOwner(this);
            }
        }else{
            this.animals = null;
        }
        return this;
    }

    /**
     * @return animals or null.
     */
    public List<DomesticAnimal> getAnimals() {
        return animals;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder();
        sb.append("Child");
        sb.append('(').append(super.toString()).append(')');
        sb.append("{animals.size=").append(animals != null ? animals.size() : "null");
        sb.append('}');
        return sb.toString();
    }
}
